<template>
  <s-layout id="layout" :title="'操作手册'" navbar="normal" leftIconColor="#333" :autoBack="false" :bgColor="state.bgColor"
    :tabbarshow='false' :titleStyle="{ color: '#333', fontSize: '32rpx' }">
    <view class="call_on" :style="{ paddingTop: (safeAreaInsets?.top + 44) + 'px' }">
      <view class="collapse">
        <scroll-view v-if="list.length" scroll-y class="comprehensive" @scrolltolower='listScrolltolower'
        show-scrollbar="true" :refresher-enabled="isOpenRefresh" :refresher-triggered="triggered"
        :refresher-threshold="100" refresher-background="white" @refresherpulling="onPulling"
        @refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="onScroll">
            <fui-collapse accordion @change="change" >
                <fui-collapse-item  :index="index" v-for="(item,index) in list" :key="index">
                  <view class="fui-item__box">
                    <image :src="item.src" class="fui-logo"></image>
                    <text>{{item.title}}</text>
                  </view>
                  <template v-slot:content>
                    <view class="fui-descr">
                      <up-parse :content="item.content"></up-parse>
                    </view>
                  </template>
                </fui-collapse-item>
              </fui-collapse>
            <!-- 加载中 && 没有更多数据了 -->
        <view>
          <s-loadmore-gather :current_page="listPage" :last_page="listlast_page" ref="loadmoreRef"></s-loadmore-gather>
        </view>
        </scroll-view>
        <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容"
        marginTop="50%"></u-empty>
      </view>
    </view>
   
  </s-layout>
</template>

<script setup>
const { safeAreaInsets } = uni.getSystemInfoSync()
const state = ref({
  bgColor: '#fff'
})
const text = ref("新增拜访");
import sheep from '@/sheep';
import { ref, reactive, unref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { baseUrl } from "@/sheep/config";
const type = ref()
onLoad((options) => {
  type.value = options.type
  listpagenumber.value = 1;
  list.value = []
  postOperationManual()

})
const loadmoreRef = ref()
//滚动触底
const listScrolltolower = () => {
  loadmoreRef.value.PopupScrolltolower()
  if (listPage.value < listlast_page.value) {
    listpagenumber.value += 1 ;
  } else {
    // isOpenRefresh.value = false
    return;
  }
  postOperationManual();
};
// 页面下拉刷新
const freshing = ref(false)
const triggered = ref(false)
const isOpenRefresh = ref(true)  // 是否开启下拉
// 自定义下拉刷新控件被下拉
const onPulling = (e) => {
  if (e.detail.deltaY < 0) return  // 防止上滑页面也触发下拉
  triggered.value = true;
}
// 自定义下拉刷新被触发
const onRefresh = () => {
  if (freshing.value) return;
  freshing.value = true;
  setTimeout(() => {
    listpagenumber.value = 1;
    list.value = []
    triggered.value = false;
    freshing.value = false;
    postOperationManual();
  }, 500);
}
// 自定义下拉刷新被复位
const onRestore = () => {
  triggered.value = 'restore'; // 需要重置
  // console.log("onRestore");
}
// 自定义下拉刷新被中止
const onAbort = () => {
  // console.log("onAbort");
}
const list = ref([])
const listPage = ref()
const listlast_page = ref();
const listpagenumber = ref(1);

const postOperationManual = async () => {
  
  let params = {
    filter: JSON.stringify({
      type: type.value?1:2,
     
    }),
    op: JSON.stringify({
      type: '=',
    
    }),
    page: listpagenumber.value,
  };
  const res = await sheep.$api.workbench.postOperationManual(params);
  console.log(res.data.rows)
  list.value = [...list.value, ...res?.data.rows];
  listPage.value = res.data.current_page
  listlast_page.value = res.data.last_page
}



</script>

<style lang="scss" scoped>
.comprehensive{
    border-radius: 16rpx;
    width: calc(100% - 40rpx);
    background-color: #fff;
    margin: 0 20rpx;
    height: 86vh;
}
//列表
.call_on {
  width: 100%;
  height: 100%;
  .collapse{
   
    // background-color: #fff;
    border-radius: 16rpx;
    margin: 30rpx auto 0 auto;
    }
    :deep(.fui-collapse__wrap){
      background-color: transparent !important;
      .fui-collapse-item__title{
        background-color: transparent !important;
      }
      .fui-descr {
        background-color: #0361ff14 !important;
      }
    }
    :deep(.fui-collapse__content-wrap){
      // height: auto !important;
    }
    :deep(.fui-logo){
      width: 0 !important;
      height: 0 !important;
    }
}
page {
		font-weight: normal;
	}

	.fui-wrap {
		padding-bottom: 64rpx;
	}

	.fui-section__title {
		margin-left: 32rpx;
	}

	.fui-item__box {
		width: 100%;
		padding: 26rpx 22rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.fui-logo {
		width: 48rpx;
		height: 48rpx;
		margin-right: 24rpx;
		display: block;
	}

	.fui-descr {
		width: 100%;
		padding: 32rpx;
		font-size: 28rpx;
		line-height: 52rpx;
		color: #7F7F7F;
		word-break: break-all;
		box-sizing: border-box;
	}
</style>